package com.ljh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ljh.pojo.SList;
import com.ljh.pojo.Song;
import com.ljh.vo.*;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface listMapper  extends BaseMapper<SList> {

    @Select("select * from list where listStyle = #{style}  order by RAND()")
    public List<SList> findListByStyle(String style);

    @Select("SELECT \n" +
            "\ts.songId,\n" +
            "\ts.songName,\n" +
            "\ts.singerName,\n" +
            "\ts.songIntroduce,\n" +
            "\tl.listTittle,\n" +
            "\tl.listIntroduce,\n" +
            "\tl.listPhoto,l.userId\n" +
            "FROM\n" +
            "\tsong s\n" +
            "LEFT OUTER JOIN \n" +
            "\tlist_song ls\n" +
            "on\n" +
            "\tls.songId = s.songId\n" +
            "LEFT OUTER JOIN\n" +
            "\tlist l\n" +
            "on\n" +
            "\tl.listId = ls.listId\n" +
            "WHERE\n" +
            "\tls.listId = #{id}")
    public List<IntoSongListVo> findSongByListId(Integer id);

    @Select("select u.userId,u.userName,u.userPhoto,ls.listTittle,ls.listIntroduce,ls.listPhoto from list ls LEFT OUTER JOIN user u on ls.userId = u.userId  where ls.listId = #{id}")
    public ListInfoTittle findSongTittleInfo(Integer id);

    @Select("select * from list order by rand() limit #{num}")
    public List<SList> findPerfer(int num);

    @Select("select * from list where userId = #{id} order by rand() limit #{num}")
    public List<SList> findNum(Integer num,Integer id);

    @Select("SELECT u1.userName,l.listTittle,l.listId,l.listPhoto from list l LEFT OUTER JOIN like1 lk on lk.listId = l.listId LEFT OUTER JOIN user u on u.userId = lk.userId LEFT OUTER JOIN user u1 on u1.userId = l.userId where u.userId = #{id} order by rand() limit 3")
    public List<MyListLike> findMyListLike(Integer id);

    @Select("select * from list where userId = #{id}")
    public List<SList> findListById(Integer id);

    @Select("select * from list l LEFT OUTER JOIN like1 lk on lk.listId = l.listId where lk.userId = #{id}")
    public List<SList> findListLikeById(Integer id);

    @Insert("insert into list (userId,listTittle,listIntroduce,listStyle,listPhoto) values (#{newList.userId},#{newList.listTittle},#{newList.listIntroduce},#{newList.listStyle},#{newList.listPhoto})")
    public void insertNewList(@Param("newList") NewList newList);

    @Insert("insert into like1 (userId,listId) values (#{userId},#{listId})")
    public void insertLike(Integer userId ,Integer listId);

    @Select("select * from like1 where userId = #{userId} and listId = #{listId}")
    public LikeUserVo findGuanxiByUserList(Integer userId,Integer listId);

    @Insert("insert into list_song (listId,songId) values (#{listId},#{songId})")
    public void insertSongToList(Integer listId,Integer songId);

    @Select("select * from list_song where listId = #{listId} and songId = #{songId}")
    public List_SongVo findListSongVo(Integer listId,Integer songId);

    @Delete("delete from list where userId = #{userId}")
    public void deleteListById(Integer userId);

    @Delete("delete from like1 where userId = #{userId}")
    public void deleteLikeById(Integer userId);

    @Delete("delete from list where listId = #{listId}")
    public void deleteListByListId(Integer listId);

    /**
     * 删除歌单和音乐中间表的内容
     * @param listId
     */
    @Delete("delete from list_song where listId = #{listId}")
    public void deleteSongListBylistId(Integer listId);

    /**
     * 通过listId来删除收藏歌单里面的歌单
     * @param listId
     */
    @Delete("delete from like1 where listId = #{listId}")
    public void deleteLikeBylistId(Integer listId);

    /**
     * 更新图片
     * @param listId
     */
    @Update("update list set listPhoto = #{listPhoto} where listId = #{listId}")
    public void updateListPhoto(String listPhoto,Integer listId);

    /**
     * 删除歌曲歌单集合中的关系
     * @param songId
     */
    @Delete("delete from list_song where songId = #{songId}")
    public void deleteListSongBySongId(Integer songId);

    /**
     * 通过listId来查询歌单
     * @param listId
     * @return
     */
    @Select("select * from list where listId = #{listId}")
    public SList findSlistByListId(Integer listId);

    /**
     * 通过songId和listId定位删除关系
     * @param songId
     * @param listId
     */
    @Delete("delete from list_song where songId = #{songId} and listId = #{listId}")
    public void deleteListInfoSong(Integer songId,Integer listId);

    @Update("update list set listTittle = #{slist.listTittle},listIntroduce = #{slist.listIntroduce},listStyle = #{slist.listStyle} where listId = #{slist.listId}")
    public void updateListInfo(@Param("slist") SList slist);

    @Select("select * from song where songName like #{songName}")
    public List<Song> findSongListInsert(String songName);

    @Insert("insert into list_song (listId,songId) values (#{listId},#{songId})")
    public void songToInsertList(Integer listId,Integer songId);

    @Select("SELECT listStyle as name,count(*) as value from list group by listStyle")
    public List<SexVo> findListStyle();
}
